import sys
sys.path.append("../reading_data")



import datetime as dt

import matplotlib

import matplotlib.pyplot as plt

from read_from_h5 import load_data

import numpy as np


def get_data_from_h5():
    h5_file = "../../bindata/short25hz.h5"
    data = load_data(h5_file, filt=["(wtcrotorspeed>17)" ])
    return data

def look_at_25hz():
    data = get_data_from_h5()
    fig, axs = plt.subplots(1,1)
    ax = axs
    print data['timestampgmt'][0]
    hest = np.array(data['timestampgmt'], dtype='f')
    print type(hest[0])
    print hest[1]
    #ax.plot(data["wtcactivepower"], marker='o')
    #time_vec = [dt.datetime.fromtimestamp(tid) for tid in data['timestampgmt']]
    #ax.plot(time_vec, data["wtcactivepower"], marker='o')
    n = len(data["toweracc1x"])
    n = 2**20
    print n
    sp = np.fft.fft(data["toweracc1x"], n=n)
    freq = np.fft.fftfreq(n)
    ax.plot(freq, sp.real)

    #plt.gca().xaxis.set_major_formatter(matplotlib.dates.DateFormatter("%H:%M:%S.%f"))
    plt.show()




def main():
    #look_at_direction()
    look_at_25hz()
    return

if __name__=='__main__':
    main()
